﻿var mongoose = require('mongoose');

var questionSchema = new mongoose.Schema({
    title: {
        type: String,
        required: true
    },
    creator: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User',
        required: true
    },
    subject: {
        type: String,
        required: true
    },
    content: {
        type: String,
        required: true
    },
    pictures: [{
        type: Buffer
    }],
    createdAt: {
        type: Date,
        default: Date.now()
    }
});

questionSchema.methods.tidyInfo = function () {
    return {
        title: this.title,
        _id: this._id,
        creatorId: this.creator,
        subject: this.subject,
        content: this.content,
        pictures: this.pictures || [],
        createdAt: this.createdAt
    };
};


module.exports = mongoose.model('Question', questionSchema, 'questions');
module.exports.questionSchema = questionSchema;